package com.mars.module.admin.controller;


import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import com.mars.common.enums.BusinessType;
import com.mars.common.result.R;
import com.mars.common.util.ExcelUtils;
import io.swagger.annotations.Api;
import com.mars.framework.annotation.RateLimiter;
import com.mars.module.admin.entity.UserFollow;
import com.mars.framework.annotation.Log;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import com.mars.common.response.PageInfo;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.mars.module.admin.service.IUserFollowService;
import com.mars.module.admin.request.UserFollowRequest;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户关注控制层
 *
 * @author mars
 * @date 2024-03-04
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = " 7.用户关注接口管理", tags = "7.用户关注接口管理")
@RequestMapping("/admin/userFollow")
public class UserFollowController {

    private final IUserFollowService iUserFollowService;

    /**
     * 分页查询 用户关注列表
     */
    @ApiOperation(value = "分页查询 用户关注列表")
    @PostMapping("/pageList")
    public R<PageInfo<UserFollow>> pageList(@RequestBody UserFollowRequest userFollowRequest) {
        return R.success(iUserFollowService.pageList(userFollowRequest));
    }

    /**
     * 获取 用户关注详细信息
     */
    @ApiOperation(value = "获取 用户关注详细信息")
    @GetMapping(value = "/query/{id}")
    public R<UserFollow> detail(@PathVariable("id") Long id) {
        return R.success(iUserFollowService.getById(id));
    }

    /**
     * 新增 用户关注
     */
    @Log(title = "新增 用户关注", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增 用户关注")
    @PostMapping("/add")
    public R<Void> add(@RequestBody UserFollowRequest userFollowRequest) {
        iUserFollowService.add(userFollowRequest);
        return R.success();
    }

    /**
     * 修改 用户关注
     */
    @Log(title = "修改 用户关注", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改 用户关注")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody UserFollowRequest userFollowRequest) {
        iUserFollowService.update(userFollowRequest);
        return R.success();
    }

    /**
     * 删除 用户关注
     */
    @Log(title = "删除 用户关注", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除 用户关注")
    @PostMapping("/delete")
    public R<Void> remove(@RequestParam(value = "followerId") String followerId, @RequestParam(value = "userId") String userId,
                          @RequestParam(value = "type") String type) {
        iUserFollowService.remove(followerId, userId, type);
        return R.success();
    }

    /**
     * 导出 用户关注
     *
     * @param response response
     * @throws IOException IOException
     */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response, @RequestBody UserFollowRequest userFollowRequest) throws IOException {
        List<UserFollow> list = iUserFollowService.list(userFollowRequest);
        ExcelUtils.exportExcel(list, UserFollow.class, " 用户关注信息", response);
    }
}
